"""
These functions are linked from runtime library
and functions in this file are called from compiler, not from user program.
"""

from .builtin_function_classes.math import *
from .builtin_function_classes.random import *
from .builtin_function_classes.container import *

from .builtin_function_classes.runtime import *


class PMBuiltins:

    def __init__(self):
        self.initiated = False

    def init(self, module: ir.Module):
        self.pm_runtime_init = PMRuntimeInit(module)

        self.malloc = Malloc(module)
        self.malloc_auto_ptr = AllocAutoPointer(module)
        self.realloc = Realloc(module)
        self.print_lf = PrintLF(module)
        self.print_integer = PrintInteger(module)
        self.print_double = PrintDouble(module)
        self.print_string = PrintString(module)
        self.raise_error = RaiseError(module)
        self.raise_index_error = RaiseIndexError(module)

        self.pow = Pow(module)
        self.sqrt = Sqrt(module)
        self.sine = Sine(module)
        self.cosine = Cosine(module)
        self.log = LogFunc(module)

        self.random_float = RandomFloat(module)
        self.random_integer = RandomInteger(module)
        self.uniform = Uniform(module)
        self.sample_index = SampleIndex(module)

        # self.new_integer_set = NewIntegerSet(module)
        # self.add_to_integer_set = AddToIntegerSet(module)
        # self.show_integer_set_elements = ShowIntegerSetElements(module)
        # self.integer_set_has = IntegerSetHasElement(module)
        # self.integer_set_free = IntegerSetFree(module)
        # self.integer_set_to_buffer = IntegerSetToBuffer(module)

        self.initiated = True

    def after_initiated(self, module: ir.Module):
        self.runtime_init = RuntimeInit(module)


builtins = PMBuiltins()
